#include <iostream>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <unistd.h>
#include <string.h>

int main()
{
    int clientSocket = socket(AF_INET, SOCK_STREAM, 0);

    sockaddr_in serverAddr;
    serverAddr.sin_family = AF_INET;
    serverAddr.sin_port = htons(8899);
    serverAddr.sin_addr.s_addr = inet_addr("127.0.0.1");

    if(connect(clientSocket, (sockaddr*)&serverAddr, sizeof(serverAddr)) < 0)
    {
        close(clientSocket);
        return -1;
    }

    char buff[128] = {'\0'};
    char buffRec[128] = {'\0'};
    while(true)
    {
        std::cin >> buff;
        std::string res = buff;
        if(res == "quit") break;
        if(send(clientSocket, buff, sizeof(buff), 0) < 0)
        {
            close(clientSocket);
            break;
        }
        memset(buffRec, 0, 128);
        if(recv(clientSocket, buff, 128, 0) > 0)
        {
            std:: cout << buff << std::endl;
        }
    }
    close(clientSocket);
    return 0;
}